<!--  -->
<template>
    <div class="my-wrap">
        <van-pull-refresh loading-text="...يۈكسىلىۋاتىدۇ" loosing-text="قويۇپ بەرسىڭىز يېڭىلىنىدۇ" success-text="تامام" v-model="isLoading" @refresh="onRefresh">
            <!-- <div class="avator">
                <img :src="userInfo.headimgurl" @click="test">
            </div> -->
            <div class="user-info" :style="{'backgroundImage':currUserInfo.isVip ? 'linear-gradient(120deg,#fff7ec,#ffcb7e)' : '' }">
                <img src="https://mars-kino.oss-cn-beijing.aliyuncs.com/static/cash-gold.png" class="vip-user" v-if="Boolean(currUserInfo.isVip)" />
                <div class="avatar">
                    <span class="vip" v-if="Boolean(currUserInfo.isVip)">
                        <i class="icon iconfont icon-vip-tianchong" />
                    </span>
                    <div class="left">
                        <img :src="currUserInfo.headimgurl">
                    </div>
                    <div class="right">
                        <div class="username">{{currUserInfo.nickName}}</div>
                        <div class="uid">ID:{{Number(currUserInfo.uid)}}</div>
                        <div class="isvip">
                            <span class="end-time" v-if="Boolean(currUserInfo.isVip)">{{formatDate(currUserInfo.endTime)}}</span>
                            <span v-if="Boolean(currUserInfo.isVip)">:ئالىي ئەزا </span>
                            <span v-else>ئادەتتىكى ئەزا </span>
                        </div>
                        <div class="isvip">
                            <span class="integral">50</span>
                            <span>:جۇغلانما </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="operate">
                <div class="order" @click="$router.push('/orderList')">
                    <span class="tubiao"><i class="icon iconfont icon-dingdan1"></i></span>
                    <span class="title">زاكاس باشقۇرۇش</span>
                </div>
                <div class="vip" @click="$router.push('/vip')">
                    <span class="tubiao"><i class="icon iconfont icon-huiyuan2"></i></span>
                    <span class="title">بولۇش VIP</span>
                </div>
                <div class="history" @click="developing">
                    <span class="tubiao"><i class="icon iconfont icon-chakan"></i></span>
                    <span class="title">كۆرگەنلىرىم</span>
                </div>
            </div>
            <div class="list">
                <div class="ever-buy" @click="$router.push('/buyVideo')">
                    <div class="left"><i class="icon iconfont icon-xiazai6"></i></div>
                    <div class="right">
                        <div>
                            <span class="tubiao">
                                <van-icon name="cart-circle-o" />
                            </span>
                            <span class="title">سېتىۋالغان ڧىلىملىرىم</span>
                        </div>
                    </div>
                </div>
                <div class="collect" @click="$router.push('/collectVideo')">
                    <div class="left"><i class="icon iconfont icon-xiazai6"></i></div>
                    <div class="right">
                        <div>
                            <span class="tubiao">
                                <van-icon name="star-o" />
                            </span>
                            <span class="title">ساقلىۋالغانلىرىم</span>
                        </div>
                    </div>
                </div>
                <div class="connect" @click="developing">
                    <div class="left"><i class="icon iconfont icon-xiazai6"></i></div>
                    <div class="right">
                        <div>
                            <span class="tubiao">
                                <van-icon name="service-o" /></span>
                            <span class="title"> ئالاقىلىشىش</span>
                        </div>
                    </div>
                </div>
                <div class="connect" @click="developing">
                    <div class="left"><i class="icon iconfont icon-xiazai6"></i></div>
                    <div class="right">
                        <div>
                            <span class="tubiao">
                                <van-icon name="gem-o" /></span>
                            <span class="title">ھەقسىز VIP</span>
                        </div>
                    </div>
                </div>
                <div class="connect" @click="developing">
                    <div class="left"><i class="icon iconfont icon-xiazai6"></i></div>
                    <div class="right">
                        <div>
                            <span class="tubiao">
                                <van-icon name="question-o" /></span>
                            <span class="title">بىز ھەققىدە</span>
                        </div>
                    </div>
                </div>
            </div>
        </van-pull-refresh>
    </div>
</template>

<script>
import { formatDate } from "../../utils";
import { Toast } from 'vant';
import { mapState} from 'vuex'
export default {
    data() {
        return {
            currUserInfo: { uid: 0 },
            isLoading: false,
            count: 0
        };
    },
    methods: {
        formatDate(val) {
            if (!val) {
                return 0;
            } else {
                let dt = new Date(Number(val));
                return `${dt.getFullYear()}-${(dt.getMonth() + 1)
                    .toString()
                    .padStart(2, 0)}-${dt
                    .getDate()
                    .toString()
                    .padStart(2, 0)}`;
            }
        },
        onRefresh() {
            this.getBaseInfo();
        },
        developing(){
            Toast('...ئىقتىدار ياسىلىۋاتىدۇ')
        },
        getBaseInfo(){
            this.isLoading = true;
            this.$http
            .get("/getBaseInfo", {
              params: {
                openid: this.$store.state.userInfo.openid
              }
            })
            .then(res => {
                this.isLoading = false;
                try {
                let userInfo = JSON.parse(this.$decrypt(res));
                if (userInfo.endTime && userInfo.endTime > Date.now()) {
                    userInfo.isVip = 1;
                }
                this.currUserInfo = userInfo;
                this.$store.commit("SET_USERINFO", userInfo);
                }
                catch (error) {
                Toast({
                  message: "توردا مەسىلە كۆرۈلدى",
                  duration: 100
                });
              }
            }).catch(err=> {
                this.isLoading = false;
            })
        }
    },
    mounted() {
        let timer = setInterval(() => {
            if (this.$store.state.userInfo) {
                this.getBaseInfo();
                clearInterval(timer);
            }
        }, 100);
    },
    computed: {
        ...mapState(['userInfo'])
    },
    watch:{
        userInfo(val) {
            this.currUserInfo = val;
        }
    }
};
</script>
<style lang='scss' scoped>
$bgColor: #1a2127;
.my-wrap {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0px;
    background-color: #fff;
    .van-icon {
        font-size: 20px;
    }
    .user-info {
        width: 100%;
        height: 230px;
        box-shadow: 0 0 20px 5px rgba(0, 0, 0, 0.2);
        border-radius: 42px;
        margin: 15px auto;
        border: 1px solid transparent;
        display: flex;
        position: relative;
        .vip-user {
            position: absolute;
            width: 100px;
            height: 100px;
            right: 4%;
            top: 28%;
            border-radius: 51%;
            // box-shadow: 0 0 11px 5px rgba(0,0,0,.15);
            object-fit:contain;
            opacity: 0.6;
        }
        .avatar {
            margin: 40px 0px 10px 30px;
            border: 2px solid transparent;
            position: relative;
            .vip {
                display: block;
                position: absolute;
                left: 87px;
                color: #ff464e;
                top: 112px;
                z-index: 2;
                border-radius: 50%;
                .iconfont {
                    font-size: 51px;
                }
            }
            .left {
                display: inline-block;
                box-sizing: border-box;
                width: 150px;
                height: 150px;
                border-radius: 50%;
                overflow: hidden;
                box-shadow: 0 0 20px 3px rgba(0, 0, 0, 0.5);
                img {
                    width: 100%;
                    height: 100%;
                }
            }
            .right {
                // display: inline-block;
                vertical-align: top;
                margin-left: 40px;
                display: inline-flex;
                flex-direction: column;
                justify-content: space-around;
                color: #40c4ff;
                height: 150px;
                direction: rtl;
                text-align: left;
                font-size: 30px;
                .end-time,
                .integral {
                    margin-left: 20px;
                }
            }
        }
    }
    .avator {
        height: 240px;
        width: 100%;
        margin-top: 20px;
        img {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border: 3px solid #f2f2f2;
            box-shadow: 0 0 8px 3px rgba(255, 255, 255, 0.2);
        }
        margin-bottom: 20px;
    }
    .operate {
        width: 100%;
        height: 170px;
        box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.15);
        border-radius: 41px;
        display: flex;
        text-align: center;
        justify-content: space-around;
        // background-color: rgb(255, 200, 0);
        background-color: #fff;

        .order,
        .history,
        .vip {
            display: flex;
            flex-direction: column;
            justify-content: center;
            .tubiao {
                color: #0081ff;
                // color: #f2f2f2;
                margin-bottom: 20px;
                .iconfont {
                    font-size: 50px;
                }
            }
            .title {
                color: #0081ff;
                // color: #f2f2f2;

                font-size: 30px;
                .iconfont {
                    font-size: 50px;
                }
            }
        }
    }
    .list {
        margin-top: 20px; // background-color: #f0f0f0;
        box-sizing: border-box;
        .ever-buy,
        .collect,
        .connect {
            height: 80px;
            width: 100%;
            display: flex;
            justify-content: space-between;
            color: #999;
            margin-bottom: 10px;
            border-radius: 15px;
            box-shadow: 0 0 10px 1px rgba(0, 0, 0, 0.15);
            .left {
                display: flex;
                justify-content: center;
                align-items: center;
                margin-left: 10px;
                .iconfont {
                    font-size: 30px;
                }
            }
            .right {
                display: flex;
                justify-content: center;
                align-items: center;
                div {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    direction: rtl;
                    .title {
                        font-size: 30px;
                    }
                    .tubiao {
                        margin: 0 15px;
                        display: inline-block;
                        width: 55px;
                        height: 55px;
                        background-color: #0081ff;
                        border-radius: 50%;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        color: #fff;
                    }
                }
            }
        }
        .connect {
            margin-bottom: 8px;
        }
    }
    .van-pull-refresh {
        width: 100%;
        height: 100%;
    }
}
</style>